//
//  CYTrendSource.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/6/20.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYTrendSource.h"
#define GAP 10 //控件距离屏幕边框的距离
#define FONT 16 //字号
#define TEXTWIDTH [@"期号" sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:FONT]}].width
#define NUMWIDTH [@"8" sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:FONT]}].width
#define DATE_maxX (2*GAP+TEXTWIDTH) //期号的maxOriginX
@interface CYTrendSource(){
    TrendType _type;
    NSString *string;
}
@end
@implementation CYTrendSource

//根据彩票名称，返回对应的类型
+ (TrendType)getType:(NSString *)lotteryName{
    if ([lotteryName containsString:@"福彩3"] || [lotteryName containsString:@"排列三"]) return DiPinCaiType;
    else if ([lotteryName containsString:@"pk"] || [lotteryName containsString:@"PK"]) return PKShiType;
    else if ([lotteryName containsString:@"快三"]) return KuaiSanType;
    else if ([lotteryName containsString:@"时时彩"]) return ShiShiCaiType;
    else if ([lotteryName containsString:@"选"]) return ShiYiXuanWuType;
    else if ([lotteryName containsString:@"时时乐"]) return ShiShiLeType;
    NSAssert((NO), @"未明确彩票的类型 --->@selector(getType:)");
    return ShiYiXuanWuType;
}

//获取彩票的位级数组
+ (NSArray *)getUnitTitles:(NSString *)lotteryName{
    if ([lotteryName containsString:@"快三"]) return @[@"开奖", @"第一位", @"第二位", @"第三位"];
    else if ([lotteryName containsString:@"选"]) return @[@"开奖", @"第一位", @"第二位", @"第三位", @"第四位", @"第五位"];
    else if ([lotteryName containsString:@"时时彩"]) return @[@"开奖", @"万位", @"千位", @"百位", @"十位", @"个位"];
    else if ([lotteryName containsString:@"福彩"] || [lotteryName containsString:@"排列三"] || [lotteryName containsString:@"时时乐"]) return @[@"开奖", @"百位", @"十位", @"个位"];
    else if ([lotteryName containsString:@"pk"] || [lotteryName containsString:@"PK"]) return @[@"开奖", @"第一位", @"第二位", @"第三位", @"第四位", @"第五位", @"第六位", @"第七位", @"第八位", @"第九位", @"第十位"];
    else return nil;
}

#pragma - mark cell 的最右边的label 的中间点X
+ (CGFloat)getRightLBLCenterX:(TrendType)type{
    if (type == ShiShiLeType) return SCREEN_WIDTH / 2.0 - (TEXTWIDTH + GAP);
    else return SCREEN_WIDTH / 2.0 - (TEXTWIDTH / 2.0 + GAP);
}

#pragma - mark cell 的右边第二个的label 的中间点X
+ (CGFloat)getRightSecLBLCenterX:(TrendType)type{
    if (type == ShiYiXuanWuType || type == DiPinCaiType || type == ShiShiLeType) return SCREEN_WIDTH / 2.0 - ([self getUnitGap:type] + TEXTWIDTH * 1.5 + GAP);
    else if (type == KuaiSanType || type == ShiShiCaiType) return SCREEN_WIDTH / 2.0 - ([self getUnitGap:type] + TEXTWIDTH * 1.5 + GAP);
    else return 0;
}

#pragma - mark cell 的中间的label 的中间点X
+ (CGFloat)getMidLBLCenterX:(TrendType)type{
    if (type == ShiShiCaiType || type == KuaiSanType) return SCREEN_WIDTH / 2.0 - ([self getUnitGap:type] * 2 + TEXTWIDTH * 2.5 + GAP);
    else return 0;
}

#pragma - mark tableview.headerView的开奖号码的label 的中间点X
+ (CGFloat)getWinNumLBLCenterX:(TrendType)type{
    if (type != PKShiType ) return ([self getWinNumLBLGap:type] + DATE_maxX) - SCREEN_WIDTH / 2.0;
    else return ([self getWinNumLBLGap:type] + DATE_maxX) - SCREEN_WIDTH / 2.0;
}

#pragma - mark cell的开奖号码的第一个label 距离父视图左边 的距离
+(CGFloat)getNumbersOriginX:(TrendType)type{
    if (type == PKShiType) return [self getUnitGap:type] + DATE_maxX + AUTO(10) * AUTO(1) * AUTO(1) * AUTO(1);
    else return [self getUnitGap:type] + DATE_maxX;
}

#pragma - mark cell的开奖号码的label与label之间的间距
+ (CGFloat)getNumbersMap:(TrendType)type{
    if (type == PKShiType) return ([self getWinNumLBLGap:type] * 2 - [self getUnitGap:type] * 2 - AUTO(10) * 2 * AUTO(1) * AUTO(1) * AUTO(1) -  NUMWIDTH * 10.0 * 2) / 9.0;
    else if (type == ShiShiCaiType) return ([self getWinNumLBLGap:type] * 2 - [self getUnitGap:type] * 2 - NUMWIDTH * 5.0) / 4.0;
    else if (type == ShiYiXuanWuType) return ([self getWinNumLBLGap:type] * 2 - [self getUnitGap:type] * 2 - NUMWIDTH * 5.0 * 2) / 4.0;
    else if (type == KuaiSanType || type == ShiShiLeType || type == DiPinCaiType) return ([self getWinNumLBLGap:type] * 2 - [self getUnitGap:type] * 2 - NUMWIDTH * 3.0) / 2.0;
    else return 0;
}
#pragma - mark cell 后面三个 控件 与 控件 的间距
+ (CGFloat)getUnitGap:(TrendType)type{
    if (type == ShiYiXuanWuType || type == DiPinCaiType || type == ShiShiLeType) return (SCREEN_WIDTH / 2.0 - GAP - TEXTWIDTH * 2) / 3;
    else if (type == KuaiSanType || type == ShiShiCaiType) return (SCREEN_WIDTH / 2.0 - GAP - TEXTWIDTH * 3) / 3;
    else  return 0;
}

#pragma - mark tableview.headerView的开奖号码的label的中间点 到两边最近的控件的等距离
+ (CGFloat)getWinNumLBLGap:(TrendType)type{
    if (type == PKShiType) return (SCREEN_WIDTH - DATE_maxX) / 2.0;
    else if (type == ShiShiCaiType || type == KuaiSanType) return ([self getMidLBLCenterX:type] + SCREEN_WIDTH / 2.0 - TEXTWIDTH / 2.0 - DATE_maxX) / 2.0;
    else if (type == ShiYiXuanWuType || type == DiPinCaiType || type == ShiShiLeType) return ([self getRightSecLBLCenterX:type] + SCREEN_WIDTH / 2.0 - TEXTWIDTH / 2.0 - DATE_maxX) / 2.0;
    else return 0;
}


#pragma - mark cell 的开奖号码 的宽度
+ (CGFloat)getNumWidth:(TrendType)type{
    if (type == PKShiType || type == ShiYiXuanWuType) return NUMWIDTH * 2.0;
    else return NUMWIDTH;
}

#pragma - mark 根据彩种类型,和开奖号码，获取走势图cell最右边label的text
+ (NSString *)getRightLBLText:(NSString *)data type:(TrendType)type{
    NSArray *array = [data componentsSeparatedByString:@","];
    if (type == ShiYiXuanWuType || type == DiPinCaiType) return [NSString stringWithFormat:@"%d",[array minus]];
    else if (type == ShiShiCaiType) return @"组三";
    else if (type == KuaiSanType) return ([array sum] % 2)?@"双":@"单";
    else if (type == ShiShiLeType) return [array sameString];
    else return nil;
}

#pragma - mark 根据彩种类型,和开奖号码，获取走势图cell右边第二个label的text
+ (NSString *)getRightSecLBLText:(NSString *)data type:(TrendType)type{
    NSArray *array = [data componentsSeparatedByString:@","];
    if (type == ShiYiXuanWuType || type == DiPinCaiType) return [NSString stringWithFormat:@"%d",[array sum]];
    else if (type == ShiShiCaiType) return @"大双";
    else if (type == KuaiSanType) return ([array sum] > 10)?@"大":@"小";
    else if (type == ShiShiLeType) return [NSString stringWithFormat:@"%d",[array sum]];
    else return nil;
}

#pragma - mark 根据彩种类型,和开奖号码，获取走势图cell中间的label的text
+ (NSString *)getMidLBLText:(NSString *)data type:(TrendType)type{
    NSArray *array = [data componentsSeparatedByString:@","];
    if (type == ShiShiCaiType) return @"小双";
    else if (type == KuaiSanType) return [NSString stringWithFormat:@"%d",[array sum]];
    else return nil;
}

#pragma - mark 从字典中获取开奖的期数
+ (NSString *)getDateLBLText:(NSString *)data type:(TrendType)type{
    return [NSString stringWithFormat:@"%@期",[data substringFromIndex:data.length - 3]];
}

+ (CGFloat)getCellNumLabelMinX:(TrendType)type count:(NSUInteger)count{
    
    CGFloat double_width = [@"88" sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}].width;
    CGFloat single_width = [@"8" sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}].width;
    /*由开奖号控件到父视图左边的距离-->得到开奖号控件的中心点*/
    CGFloat num_centerX = [self getWinNumLBLCenterX:type];
    /*号码之间的间隙*/
    CGFloat map = 5;
    /*两位数号码的起始控件左边到父视图左边的距离*/
    CGFloat double_width_map = (count%2)?(num_centerX-count/2.0*double_width - map*count/2):(num_centerX-double_width*count/2-map*count/2.0);
    /*一位数号码的起始控件左边到父视图左边的距离*/
    CGFloat single_width_map = (count%2)?(num_centerX-count/2.0*single_width - map*count/2):(num_centerX-single_width*count/2-map*count/2.0);
    /*pk拾起始控件到父视图左边的距离*/
    CGFloat pkNum_width_map = (SCREEN_WIDTH - TEXTWIDTH * 0.5 - double_width * (2 + count) - 10 - (count - 1) * map) / 2.0 + 10 + double_width * 1.5 + TEXTWIDTH * 0.5;
    if (type == ShiYiXuanWuType)
        return double_width_map;
    else if (type == DiPinCaiType || type == KuaiSanType || type == ShiShiCaiType || type == ShiShiLeType)
        return single_width_map;
    else if (type == PKShiType)
        return pkNum_width_map;
    //    else if (type == ShiShiCaiType)
    //        return (double_width_map + single_width_map) / 2.0;
    NSAssert(NO, @"未明确的type或者  -->时时彩票种类  -->@selector(getCellNumLabelMinX:) ");
    return 0;
}
@end
